#include"d.h"
void Init(Que* pq)
{
	assert(pq);
	pq->head = pq->tail = NULL;
	pq->size = 0;

}
void Destory(Que* pq)
{
	assert(pq);
	QNode* cur = pq->head;
	while (cur)
	{
		QNode* next = cur->next;
		free(cur);
		cur = next;
	}
	pq->head = pq->tail = NULL;
	pq->size = 0;
}
void Push(Que* pq, QDataType x)
{
	assert(pq);
	QNode* newnode = (QNode*)malloc(sizeof(QNode));
	if (newnode == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}
	newnode->data = x;
	newnode->next = NULL;
	if (pq->tail == NULL)
	{
		pq->head = pq->tail = newnode;

	}
	else
	{
		pq->tail->next = newnode;
		pq->tail = newnode;
	}
	pq->size++;

}
void Pop(Que* pq)
{
	assert(pq);
	assert(!Empty(pq));
	if (pq->head->next == NULL)
	{
		free(pq->head);
		pq->head = pq->tail = NULL;

	}
	else
	{
		QNode* next = pq->head->next;
		free(pq->head);
		pq->head = next;
	}
	pq->size--;
}
QDataType Front(Que* pq)
{
	assert(pq);
	assert(!Empty(pq));
	return pq->head->data;
}
QDataType Back(Que* pq)
{
	assert(pq);
	assert(!Empty(pq));
	return pq->tail->data;
}
bool Empty(Que* pq)
{
	assert(pq);
	return pq->head == NULL;
}
int Size(Que* pq)
{
	assert(pq);
	return pq->size;
}
